<!--客户流失列表  ————————  客户经理可查看-->
<template>
  <div id="CustomerDrainList">
    <!--         Breadcrumbs -->
    <div class="breadcrumbs" style="margin: 0px;padding-top: 20px;">
      <ul>
        <li class="home"><a href="index.html" title="Go to Home Page"><strong style="font-size: 18px;">客户管理</strong></a>
          <span>/</span>
        </li>
        <li><strong>客户流失管理</strong><span>/</span></li>
        <li><strong>客户流失列表</strong></li>
      </ul>
    </div>
    <article class="col-main">
      <div class="my-account block block-account" style="padding-left: 20px;padding-right: 20px;">
        <div style="padding: 20px 20px 30px 20px">
          <span style="font-size: 30px;font-weight: bolder">客户流失列表</span>
        </div>

        <form action="">
            <div class="row" style="margin-bottom: 30px">
              <div class="col-sm-3 col-md-3"></div>
              <div class="col-sm-1 col-md-1 text-center" style="padding: 0px">
                <h4>客户:</h4>
              </div>
              <div class="col-sm-3 col-md-3">
                <input v-model="Vo.customerName" class="form-control" placeholder="请输入客户名称" style="width: 180px;">
              </div>

              <div class="col-sm-1 col-md-1 text-center" style="padding: 0px">
                <h4>状态:</h4>
              </div>
              <div class="col-sm-2 col-md-2">
                <select v-model="Vo.customerState" class="form-control" style="width: 100px">
                  <option value="" >-全部-</option>
                  <option v-for="item in customerStates" :value="item.dictionaryValue">{{item.dictionaryEntry}}</option>
                </select>
              </div>
              <div class="col-sm-2 col-md-2">
                <button v-on:click="loadDrainCustomers" class="btn btn-primary">查询</button>
              </div>
            </div>

        </form>

        <table class="table">
          <thead>
          <tr>
            <th>编号</th>
            <th>客户</th>
            <th>上次下单时间</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="(item,index) in drainCustomers">
            <th scope="row">{{index+1+(current-1)*10}}</th>
            <td>{{item.customerName}}</td>
            <td>{{item.orderUpadateTime}}</td>
            <td>{{item.customerState}}</td>
            <td>
              <button v-show="item.customerState != '确认流失' " class="btn btn-default btn-sm">暂缓</button>
<!--              <router-link to="SuspendCustomerDrain" ></router-link>-->
              <button v-show="item.customerState == '暂缓流失'" class="btn btn-primary btn-sm">确认</button>

<!--              <router-link to="ConfirmCustomerDrain"></router-link>-->
            </td>
          </tr>
          </tbody>
        </table>
        <div class="block text-center">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>

      <div class="modal fade" id="loadToBeConfirmedCustomerNum" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">提示</h5>
              <button type="button" class="close" data-dismiss="modal"
                      aria-hidden="true">&times;
              </button>
            </div>
            <div class="modal-body">
              <p id="errMsg"></p>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-primary"
                      data-dismiss="modal">确认
              </button>
            </div>
          </div>
        </div>
      </div>
    </article>
  </div>
</template>

<script>
export default {
  name: "CustomerDrainList",
  data(){
    return{
      currentPage: 1,
      limit:10,
      current:1,
      total:0,
      managers:[],
      customerStates:[],
      drainCustomers:[],
      Vo:{
        customerName:'',
        customerState:'',
        staffId:''
      },
      role:'',
      toBeConfirmedCustomerNum:0
    }
  },
  methods:{
    loadRoleAndStaffId(){
      this.role=localStorage.getItem("role")
      this.Vo.staffId=this.$store.getters.getStaff.staffId
    },
    loadCustomerStates(){
      this.$axios.get('/dictionary/loadCustomerStates').then(
        res=>{
          this.customerStates=res.data.data
        }
      )
    },
    handleSizeChange(val) {
      this.limit = val;
      this.loadDrainCustomers()
    },
    handleCurrentChange(val) {
      this.current = val;
      this.loadDrainCustomers()
    },
    loadDrainCustomers(){
      this.$axios.get('/customer/getDrainCustomers',{
        params:{
          limit:this.limit,
          current:this.current,
          customerName:this.Vo.customerName,
          customerState:this.Vo.customerState,
          staffId:this.Vo.staffId
        }
      }).then(
        res=>{
          this.drainCustomers=res.data.data.myData
          this.total=res.data.data.total
          console.log(res.data.data)
        }
      )
    },
    loadToBeConfirmedCustomerNum(){
      this.$axios.get('/customer/getToBeConfirmedCustomerNum',{
        params:{
          staffId:this.Vo.staffId
        }
      }).then(
        res=>{
          this.toBeConfirmedCustomerNum=res.data.data
          $("#errMsg").html("您有 " + this.toBeConfirmedCustomerNum +" 个客户状态为待确认的客户还未处理，请及时处理 ");
          if (this.toBeConfirmedCustomerNum>0) {
            $("#loadToBeConfirmedCustomerNum").modal('show')
          }
        }
      )
    },
  },
  created() {
    this.loadCustomerStates()
    this.loadRoleAndStaffId()
    this.loadDrainCustomers()
    this.loadToBeConfirmedCustomerNum()
  }
}
</script>

<style scoped>

</style>
